﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Xml.Linq;

namespace Soket_MMTNC_Server
{
    /// <summary>
    /// Interaction logic for Productwindows.xaml
    /// </summary>
    public partial class Productwindows : Window
    {
        public Productwindows()
        {
            InitializeComponent();
            Load();
        }
        Product p = new Product();
        private void Load()
        {
            if (Products.check != 0)
            {
                p=p.GetItem(Products.check);
                txt_id.Text = p.ProductID.ToString();
                txt_name.Text = p.ProductName;
                txt_price.Text = p.Price;               
                cbo_unit.Text = p.UnitPrice;
            }
        }
        private void button2_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }
        
        private void button1_Click(object sender, RoutedEventArgs e)
        {
            if (Products.check != 0)
            {
                p.UpdateData(int.Parse(txt_id.Text.Trim()), txt_name.Text.Trim(), txt_price.Text.Trim(),
                                cbo_unit.Text);
                Products.me.Load();
                this.Close();
            }
            else
            {
                p.InsertData(txt_name.Text.Trim(), txt_price.Text.Trim(), cbo_unit.Text);
            }
        }
    }
}
